import json as js

import common.OsUtil  as ut

#审计学
path="\\"
os_path = ut.OsUtil(path)

sc_all_list = os_path.dir_scan(dir_path=path, postfix=".json")

dic_answer_key_mapping = {"SINGLE_CHOICE": "单选", "MULTIPLE_CHOICE": "多选", "TRUE_OR_FALSE": "判断", "ESSAY": "问答"}


def answer_type_mapping(type, answer_value):
    return None


def open_read_file(path):
    open_file = open(path, "r", encoding="utf-8")
    all_lines = open_file.readlines()
    open_file.close()
    rt_value = None
    if len(all_lines) > 1:
        rt_value = all_lines[1]
    else:
        rt_value = all_lines[0]
    return rt_value

# //\n\na）
answer_value_replace_set = ["<p>", "<span>", "</p>", "</span>","[","]","\\n","\\na"]


def answer_value_replace(str_value):
    for item in answer_value_replace_set:
        str_value = str(str_value).replace(item, "")
    return str_value


show_answer_key = []
answer_sum_count=0

for item in sc_all_list:
    # print(item)
    answer_json_obj = js.loads(open_read_file(item))
    answer_question_list = answer_json_obj["masterVersion"]["questionUnitList"]
    for question_item in answer_question_list:
        answer_type = str(dic_answer_key_mapping.get(question_item["questionType"]))
        answer_title_body = answer_value_replace(question_item["body"])
        answer_title_value_obj = answer_value_replace(str(question_item["rightAnswer"]))
        answer_body_desc = []
        answer_title_body_obj = question_item["questionOptionList"]
        if answer_title_body_obj is not None:
            index_value=0
            for body_item in answer_title_body_obj:
                answer_body_desc.append(str(index_value)+" ："+ str(body_item["body"]))
                index_value=index_value+1

        answer_sum_count=answer_sum_count+1
        print("")
        # if  str(question_item["questionType"]) not in show_answer_key:
        print('题类型：' + str(answer_type))
        # show_answer_key.append(question_item["questionType"])
        print("题目描述:" + answer_title_body)
        if str(question_item["questionType"]) in ["MULTIPLE_CHOICE","SINGLE_CHOICE"]:
            print("题目选项：" + answer_value_replace(str(answer_body_desc)))
        print("题目答案：" + str(answer_title_value_obj))

print("totlal   "+str(answer_sum_count))
